﻿using System.Collections.ObjectModel;
using System.Windows.Media;
using System.Windows.Shapes;
using MaxStoreErp.Core.Threading;
using MaxStoreErp.Core.Ui.MainMenu;

namespace MaxStoreErp.Core.Services
{
    public class MainMenuService : IMainMenuService
    {
        public MenuItemsCollection Items { get; private set; }
        readonly ObservableCollection<IMainMenuElement> _mainMenuElements;

        public MainMenuService()
        {
            _mainMenuElements = new ObservableCollection<IMainMenuElement>();
            Items = new MenuItemsCollection(_mainMenuElements);
        }

        public void Add(IMainMenuElement menuElement)
        {
            ThreadHelper.SafeCall(
                () =>
                    _mainMenuElements.Add(new MenuItemControl
                    {
                        GroupName = menuElement.GroupName,
                        Title = menuElement.TileCaption,
                        Content = new Path { Stretch = Stretch.Uniform, Data = menuElement.IconData, Fill = new SolidColorBrush(Colors.White), Width = 48, Height = 48 },
                        Command = menuElement.Command
                    }));
        }

        public void Remove(IMainMenuElement menuElement)
        {
            ThreadHelper.SafeCall(() =>
                _mainMenuElements.Remove(menuElement));
        }
    }
}
